'use strict';

function TwoStackQueue(){
	this.popStack = [];
	this.pushStack = [];
}

TwoStackQueue.prototype.add = function(value){
	this.pushStack.push(value);
}

TwoStackQueue.prototype.poll = function(){
	this.reverse();
	return this.popStack.pop();
}

TwoStackQueue.prototype.peek = function(){
	this.reverse();
	return this.popStack[this.popStack.length-1];
}

TwoStackQueue.prototype.reverse = function(){
	if( this.popStack.length===0 && this.pushStack.length===0 ){
		throw new Error(' your queue is empty');
	} else if( this.popStack.length ===0 ){
		while( this.pushStack.length!==0 ){
			this.popStack.push( this.pushStack.pop() );
		}
	}
}


var idx;
var queue = new TwoStackQueue();
queue.add(1);
queue.add(2);
queue.add(3);

for( idx=0;idx<3;idx++ ){
	console.log( queue.poll() );
}
